package com.volcreate.exception_collection.no6;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zxc
 * @date 2020/10/6
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        double[] arr = new double[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextDouble();
        }
        scanner.nextLine();

        int begin;
        int end;
        while (true) {
            String s = scanner.nextLine();
            String[] split = s.split("\\s");
            if (!split[0].matches(".*\\d")) {
                break;
            }

            begin = Integer.parseInt(split[0]);
            end = Integer.parseInt(split[1]);
            try {
                System.out.println(ArrayUtils.findMax(arr, begin, end));
            } catch (Exception e) {
                System.out.println(e);
            }

        }

        try {
            System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class, int.class, int.class));
        } catch (Exception e1) {
        }
    }
}

class ArrayUtils {

    public static double findMax(double[] arr, int begin, int end) throws IllegalArgumentException {
        if (begin >= end) {
            throw new IllegalArgumentException("begin:" + begin + " >= end:" + end);
        }
        if (begin < 0) {
            throw new IllegalArgumentException("begin:" + begin + " < 0");
        }
        if (end > arr.length) {
            throw new IllegalArgumentException("end:" + end + " > arr.length");
        }
        double[] doubles = Arrays.copyOfRange(arr, begin, end);
        double asDouble = Arrays.stream(doubles).max().getAsDouble();
        return asDouble;
    }
}
